<template>
  <div style="height: 100%">
    <el-container style="height: 100%; border: 1px solid #eee">
      <el-aside :width="sideWidth+'px'" style="background-color: rgb(238, 241, 246); height: 100%; box-shadow: 2px 0 6px rgba(0,21,41,.35);overflow: hidden;">
<Aside :isCollapse:="isCollapse" :logoTextShow="logoTextShow"/>
      </el-aside>

      <el-container>
        <el-header style="border-bottom: 1px solid #ccc;">
<Head :collapseBtnClass="collapseBtnClass" :collapse="isCollapse" :user="user" />
        </el-header>
<div>

</div>
        <el-main>
            <router-view @refreshUser="getUser"/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
  import Aside from "@/components/Aside";
  import Head from "@/components/Head";
  import request from "@/utils/request";
  export default {
    data() {
      const item = {
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      };
      return {
        tableData: Array(10).fill(item),
          collapseBtnClass:"el-icon-s-fold",
        isCollapse:false,
        sideWidth:200,
        logoTextShow : true,
        headerBg:"headerBg",
        user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {}

      }
    },
    components: {
      Aside,
        Head
    },

    methods: {
        collapse() {
            this.isCollapse = !this.isCollapse
            if (this.isCollapse) {
                this.sideWidth = 64
                this.collapseBtnClass = "el-icon-s-unfold"
                this.logoTextShow = false
            } else {
                this.sideWidth = 200
                this.collapseBtnClass = "el-icon-s-fold"
                this.logoTextShow = true
            }


        },
        getUser() {
            let username = localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")).username : ""
            if (username) {
                // 从后台获取User数据
                request.get("/user/username/" + username).then(res => {
                    // 重新赋值后台的最新User数据
                    this.user = res.data
                })
            }
        }
    }
  }
</script>
<style>
    .headerBg{
        background: #eee !important;
    }
</style>
